package com.manager.util;

import com.manager.util.mail.MailSenderInfo;
import com.manager.util.mail.SimpleMailSender;

/**
 * 邮件发送
 * @author collonn
 */
public class MailUtil {
	/**
	 * @param toAddress 接收邮件人的地址，多个收件人可以用","隔开
	 * @param subject 邮件主题
	 * @param content 邮件内容
	 * @param isHtml 发送text格式的内容还是发送html格式的内容, true:html, false:text
	 * @return boolean
	 */
	public static boolean sendMail(String toAddress, String subject, String content, boolean isHtml){
		MailSenderInfo mailInfo = new MailSenderInfo();
		mailInfo.setMailServerHost(CONSTANT.MAIL_SERVER_CONFIG.HOST);
		mailInfo.setMailServerPort(CONSTANT.MAIL_SERVER_CONFIG.PORT);
		mailInfo.setValidate(CONSTANT.MAIL_SERVER_CONFIG.VALIDATE);
		mailInfo.setUserName(CONSTANT.MAIL_SERVER_CONFIG.USERNAME);
		mailInfo.setPassword(CONSTANT.MAIL_SERVER_CONFIG.PASSWORD);
		mailInfo.setFromAddress(CONSTANT.MAIL_SERVER_CONFIG.FROM_ADDRESS);
		mailInfo.setToAddress(toAddress);
		mailInfo.setSubject(subject);
		mailInfo.setContent(content);
		
		try{
			if(isHtml == true){//发送text格式的内容
				SimpleMailSender.sendHtmlMail(mailInfo);
			}
			if(isHtml == false){//发送html格式的内容
				SimpleMailSender.sendTextMail(mailInfo);
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return true;
	}
	
	public static void main(String[] args){
		String subject = "From Java Mail";
		String content = "JUST A TEST<b>This is just a test from java mail</b><br /> <a href='http://www.baidu.com'>百度</a>";
		MailUtil.sendMail("collonn@126.com", subject, content, false);
	}
}
